import 'package:common_utils/common_utils.dart';
import 'package:flutter_deer/generated/json/base/json_field.dart';
import 'package:flutter_deer/generated/json/get_config_guns_entity.g.dart';
import 'dart:convert';

import 'package:flutter_deer/util/input_formatter/mny_format.dart';
export 'package:flutter_deer/generated/json/get_config_guns_entity.g.dart';

@JsonSerializable()
class GetConfigGunsEntity {
	String? businessCode = '';
	String? categoryCode = '';
	String? categoryId = '';
	List<String>? categoryIds = [];
	String? envLevel = '';
	String? envLevelName = '';
	String? goodsShortName = '';
	String? goodsSkuId = '';
	String? goodsSkuName = '';
	String? goodsSkuPrice = '';
	int? scanCode = 0;
	List<ShelfBean>? shelfList = [];
	String? standard = '';
	String? standardName = '';
	String? unit = '';
	String? unitName = '';

	GetConfigGunsEntity();

	factory GetConfigGunsEntity.fromJson(Map<String, dynamic> json) => $GetConfigGunsEntityFromJson(json);

	Map<String, dynamic> toJson() => $GetConfigGunsEntityToJson(this);

	// 获取格式化后的金额
	String get formatPrice {
		return '${goodsSkuPrice?.formatYuan?? ''}元/$unitName';
	}

	@override
	String toString() {
		return jsonEncode(this);
	}
}

@JsonSerializable()
class ShelfBean {
	String? goodsSkuId = '';
	String? shelfId = '';
	String? shelfName = '';
	int? shelfNo = 0;

	//自定义几个字段
	// @Ignore
	// var choose: Boolean = false         //自定义字段 是否选中
	// @Ignore
	// var orderCount: Int = 0             //自定义字段 订单数目
	// //单价转化为分
	// fun getPrice(): Int {
	// return PriceUtils.multiply100PreciseToInt(goodsSkuPrice)
	// }

	String? goodsShortName = '';
	String? goodsSkuPrice = '';//单价 单位：元
	String? goodsSkuName = '';
	String? categoryId = '';
	String? unitName = '';
	bool? choose = false;
	int? orderCount = 0;

	//单价转化为分
	int? getPriceFen() {
		return MoneyUtil.changeY2F(goodsSkuPrice ?? '0');
	}

	ShelfBean();

	factory ShelfBean.fromJson(Map<String, dynamic> json) => $ShelfBeanFromJson(json);

	Map<String, dynamic> toJson() => $ShelfBeanToJson(this);

	@override
	String toString() {
		return jsonEncode(this);
	}
}

/// gun信息管理
class UserGunManager {
  static UserGunManager? _instance;
  static UserGunManager getInstance() {
    return _instance ??= UserGunManager._internal();
  }
  UserGunManager._internal();
  /// 枪信息
  List<GetConfigGunsEntity> gunList = [];
  /// 枪信息
  List<ShelfBean> shelfList = [];
  /// 枪信息
  List<ShelfBean> shelfListByGunId = [];

}